
#include "stdafx.h"
#include "mimosav2client.h"
#include "mimosav2clientDlg.h"


#define	CFG_COMMON			_T("Common")
#define	CFG_DEBUG			_T("Debug")

#define	DEF_SERVER			_T("takip.is-by.us")
#define	DEF_USERNAME		_T("0x0011")
#define	DEF_PASSWORD		_T("8288")
#define	DEF_STUN			_T("")
#define	DEF_SOUNDIN			_T("")
#define	DEF_SOUNDOUT		_T("")
#define	DEF_COMPORT			_T("")
#define	DEF_HTTPSERVER		_T("http://takip.is-by.us:8280/WebAPI.aspx")


void Cmimosav2clientDlg::loadConfig()
{
	TCHAR szText[MAX_PATH] = {0,};
	DWORD dwCount;

	if (theApp.m_strServer.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("Server"), DEF_SERVER, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strServer = szText;
	}
	if (theApp.m_strUsername.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("Username"), DEF_USERNAME, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strUsername = szText;
	}
	if (theApp.m_strPassword.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("Password"), DEF_PASSWORD, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strPassword = szText;
	}
	if (theApp.m_strStun.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("Stun"), DEF_STUN, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strStun = szText;
	}
	if (theApp.m_strSoundIn.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("SoundIn"), DEF_SOUNDIN, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strSoundIn = szText;
	}
	if (theApp.m_strSoundOut.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("SoundOut"), DEF_SOUNDOUT, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strSoundOut = szText;
	}
	if (theApp.m_strComport.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("Comport"), DEF_COMPORT, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strComport = szText;
	}
	if (theApp.m_strHttpServer.IsEmpty())
	{
		dwCount = GetPrivateProfileString(CFG_COMMON, _T("HttpServer"), DEF_HTTPSERVER, szText, _countof(szText), theApp.m_strIniFile);
		szText[dwCount] = NULL;
		theApp.m_strHttpServer = szText;
	}

	dwCount = GetPrivateProfileString(CFG_DEBUG, _T("IsDbg"), _T("0"), szText, _countof(szText), theApp.m_strIniFile);
	szText[dwCount] = NULL;
	theApp.m_bIsDbg = _ttoi(szText) ? TRUE : FALSE;
	dwCount = GetPrivateProfileString(CFG_DEBUG, _T("DbgPhoneMac"), _T(""), szText, _countof(szText), theApp.m_strIniFile);
	szText[dwCount] = NULL;
	theApp.m_strDbgPhoneMac = szText;
	dwCount = GetPrivateProfileString(CFG_DEBUG, _T("DbgPhoneNum"), _T(""), szText, _countof(szText), theApp.m_strIniFile);
	szText[dwCount] = NULL;
	theApp.m_strDbgPhoneNum = szText;
}

void Cmimosav2clientDlg::saveConfig()
{
	WritePrivateProfileString(CFG_COMMON, _T("Server"), theApp.m_strServer, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_COMMON, _T("Username"), theApp.m_strUsername, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_COMMON, _T("Password"), theApp.m_strPassword, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_COMMON, _T("Stun"), theApp.m_strStun, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_COMMON, _T("SoundIn"), theApp.m_strSoundIn, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_COMMON, _T("SoundOut"), theApp.m_strSoundOut, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_COMMON, _T("Comport"), theApp.m_strComport, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_COMMON, _T("HttpServer"), theApp.m_strHttpServer, theApp.m_strIniFile);

	WritePrivateProfileString(CFG_DEBUG, _T("IsDbg"), (theApp.m_bIsDbg ? _T("1") : _T("0")), theApp.m_strIniFile);
	WritePrivateProfileString(CFG_DEBUG, _T("DbgPhoneMac"), theApp.m_strDbgPhoneMac, theApp.m_strIniFile);
	WritePrivateProfileString(CFG_DEBUG, _T("DbgPhoneNum"), theApp.m_strDbgPhoneNum, theApp.m_strIniFile);
}
